#!/usr/bin/env ruby
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
# frozen_string_literal: true

require 'set'
require_relative '../defconfig'

docker_rm 'send-mail'

names = Set.new %w[
  LOCAL_SEND_MAIL_PORT
  LOCAL_ROBOT_EMAIL_ADDRESS
  REDIS_PORT
]

defaults = relevant_defaults(names)

cmd = %W[
  docker run
  --restart=always
  --name=send-mail
  -u nobody
  -d
  -e CCI_SRC=/c/compass-ci
  -e SEND_MAIL_PORT=#{defaults['LOCAL_SEND_MAIL_PORT']}
  -e ROBOT_EMAIL_ADDRESS=#{defaults['LOCAL_ROBOT_EMAIL_ADDRESS']}
  -p #{defaults['LOCAL_SEND_MAIL_PORT']}:#{defaults['LOCAL_SEND_MAIL_PORT']}
  -v #{ENV['CCI_SRC']}:/c/compass-ci
  -v /etc/localtime:/etc/localtime:ro
  -w /c/compass-ci/container/send-mail
  send-mail
]

cmd += ['ruby', 'send-mail.rb']

system(*cmd)
